import React, { useCallback } from 'react';
import useRefState from './use-ref-state'; // 假设这个文件是 JS 或可以直接导入
import useUnmountedRef from './use-unmounted-ref'; // 假设这个文件也是 JS 或可以直接导入

const useSetState = (initialState = {}) => {
  const unmountedRef = useUnmountedRef();
  const [state, setState, ref] = useRefState(initialState);

  const setMergeState = useCallback((patch) => {
    if (unmountedRef.current) return;
    setState(prevState => ({
      ...prevState,
      ...(typeof patch === 'function' ? patch(prevState) : patch),
    }));
  }, []);

  return [state, setMergeState, ref];
};

export default useSetState;
